﻿Imports QLTHUVIEN.BUS
'Imports QLTHUVIEN.DAO
Imports QLTHUVIEN.DTO

Public Class frmNhaXuatBan

    Private Sub layDanhSach()
        Dim NhaXuatBanBus As NhaXuatBanBUS = New NhaXuatBanBUS()
        Dim data As DataTable = NhaXuatBanBus.LayDanhSach()
        dtgDanhSachNhaXuatBan.DataSource = data
    End Sub

    Private Sub frmNhaXuatBan_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        layDanhSach()
    End Sub

    Private Sub btnThem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThem.Click
        If txtTenNhaXuatBan.Text = "" Then
            Return
        End If

        Dim NhaXuatBanDto As New NhaXuatBanDTO()
        NhaXuatBanDto.TenNhaXuatBan = txtTenNhaXuatBan.Text

        Dim nxbBus As New NhaXuatBanBUS()
        nxbBus.ThemNhaXuatBan(NhaXuatBanDto)

        layDanhSach()
    End Sub

    Private Sub btnSua_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSua.Click
        If txtTenNhaXuatBan.Text = "" Or txtMaNhaXuatBan.Text = "" Then
            Return
        End If

        Dim NhaXuatBanDto As New NhaXuatBanDTO()
        NhaXuatBanDto.MaNhaXuatBan = txtMaNhaXuatBan.Text
        NhaXuatBanDto.TenNhaXuatBan = txtTenNhaXuatBan.Text

        Dim nxbBus As New NhaXuatBanBUS()
        nxbBus.SuaNhaXuatBan(NhaXuatBanDto)

        layDanhSach()
    End Sub

    Private Sub dtgDanhSachNhaXuatBan_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dtgDanhSachNhaXuatBan.CellClick
        txtMaNhaXuatBan.Text = dtgDanhSachNhaXuatBan.CurrentRow.Cells(0).Value.ToString()
        txtTenNhaXuatBan.Text = dtgDanhSachNhaXuatBan.CurrentRow.Cells(1).Value.ToString()
    End Sub

    Private Sub btnXoa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXoa.Click
        Dim NhaXuatBanDto As New NhaXuatBanDTO()
        NhaXuatBanDto.MaNhaXuatBan = txtMaNhaXuatBan.Text
        NhaXuatBanDto.TenNhaXuatBan = txtTenNhaXuatBan.Text
        NhaXuatBanDto.IsDelete = True

        Dim nxbBus As New NhaXuatBanBUS()
        nxbBus.XoaNhaXuatBan(NhaXuatBanDto)

        layDanhSach()
    End Sub

End Class